﻿using System;
using _5E.Infrastructure.Collections;
using Melee.Contract;
using Melee.Controller.Request;
using Melee.Controller.Routing;
using Melee.DataContract.Messaging;

namespace Melee.Controller.Handlers
{
    public class GetInitializationDataHandler : RequestHandler
    {
        private IGameService m_gameService = null;

        public GetInitializationDataHandler(IGameService gameService)
            : base(Routes.GET_INITIALIZATION_DATA)
        {
            m_gameService = gameService;
        }

        public override void Handle(WebRequest webRequest)
        {
            Handle(webRequest, rq =>
            {
                GetInitializationDataRequest request = new GetInitializationDataRequest
                {
                    LoginId = rq.Cookie.LoginId,
                    WindowWidth = webRequest.QueryArguments.ExtractFor<Int32>("width"),
                    WindowHeight = webRequest.QueryArguments.ExtractFor<Int32>("height")
                };
                return m_gameService.GetInitializationDataBy(request);
            }, rp => rp.InitializationData);
        }
    }
}
